home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: beginner question - typecasting
- Date: 04 Jan 1996 20:10:12 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan4211012@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4cei1r$s02@sun.cis.smu.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: dbowman@post.smu.edu's message of 3 Jan 1996 12:31:23 -0600
-
- In article <4cei1r$s02@sun.cis.smu.edu> dbowman@post.smu.edu (Damon Bowman) writes:
-
- When you are typecasting, is there any difference between:
-
- a = int(x)
- and
- a = (int) x
-
- My book (Teach Yourself Visual C++ 1.5 in 21 Days, Revised Edition, by
- Shammas) says both forms are supported, but doesnÆt say which should
- be used, or if it matters.
-
- The specific example given is:
-
- int i = 2;
- float a, b;
- a = float(i);
- b = (float) i;
-
- In this example, would a and b return the same value and have the same
- data type (float)?
-
- Yes.
- For builtin-types there is no difference between these two variants.
- Because 'int' and 'float' are builtin-types both statements have the
- same effect.
- For an arbitary user-defined class T the former uses a ctor with an
- argument of typeof(x), while the latter expects a conversion operator.
-
- Enno
-
-